//1. To get form .day files
//2. To read first 32 byte
//3. Every 4 byty to int32
//4. Echo int32

package main

import (
	"bufio"
	"encoding/binary"
	"fmt"
	"io"
	"os"
)

/**
type ByteOrder interface {
    Uint16([]byte) uint16
    Uint32([]byte) uint32
    Uint64([]byte) uint64
    PutUint16([]byte, uint16)
    PutUint32([]byte, uint32)
    PutUint64([]byte, uint64)
    String() string
}
*/

func main() {
	//buff.

	var path string
	path = "../data/sh000001.day"
	file, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	//var bufReader bufio.Reader
	//bufReader = bufio.NewReader(file) //errs using

	bufReader := bufio.NewReader(file)
	buf := make([]byte, 1024)
	type bbuf [4]byte
	var b1 []bbuf
	for {
		readNum, err := bufReader.Read(buf)
		if err != nil && err != io.EOF {
			panic(err)
		}
		if 0 == readNum {
			break
		}
	}

	//	day1 := int32(buf[:3])
	fmt.Printf("buf size is %d, the First 32 is /v  \n", len(buf), buf[:32])
	//fmt.Println("---", data1, "---", data2)
	//fmt.Printf("First/v", buf)
	//	var mySlice = []byte{244, 244, 244, 244, 244, 244, 244, 244}
	//	data := binary.BigEndian.Uint64(mySlice)
	var mySlice1 = []byte{88, 239, 51, 1}
	var mySlice2 = []byte{1, 51, 239, 88}

	data1 := binary.BigEndian.Uint32(mySlice1)
	data2 := binary.BigEndian.Uint32(mySlice2)
	fmt.Println(b1)
	fmt.Println("---", data1, "---", data2)

	//Stuct to byte:
	/*
		buf := new(bytes.Buffer)
		var data = []interface{}{
			uint16(61374),
			int8(-54),
			uint8(254),
		}
		for _, v := range data {
			err := binary.Write(buf, binary.LittleEndian, v)
			if err != nil {
				fmt.Println("binary.Write failed:", err)
			}
		}
		fmt.Printf("%x", buf.Bytes())
		fmt.Println(buf.Bytes())
	*/

}
